/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package olympicgamesgui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.border.EtchedBorder;

/**
 *
 * @author Fabio Mendonca
 */

public class StatusBar extends JPanel {
    
    private JLabel left,center;
    private ClockLabel right;
    /** Creates a new instance of StatusBar */
    public StatusBar() {
        super();
        super.setPreferredSize(new Dimension(6, 20));
        setLayout(new BorderLayout());
        setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        left = new JLabel("",JLabel.CENTER);
        left.setPreferredSize(new Dimension(100, 19));
        left.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        center = new JLabel("");
        center.setPreferredSize(new Dimension(320, 19));
        center.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        right = new ClockLabel();
        right.setPreferredSize(new Dimension(200, 19));
        right.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        add(left, BorderLayout.WEST);
        add(center, BorderLayout.CENTER);
        add(right, BorderLayout.EAST);
    }

    /**
     * @param left the left to set
     */
    public void setLeft(String txt) {
        left.setText(txt);
    }

    /**
     * @param center the center to set
     */
    public void setCenter(String txt) {
        center.setText(txt);
    }

    /**
     * @param right the right to set
     */
    public void setRight(String txt) {
        right.setText(txt);
    }
    private class ClockLabel extends JLabel implements ActionListener {

  public ClockLabel() {
    super("" + new Date());
    Timer t = new Timer(1000, this);
    t.start();
  }

  public void actionPerformed(ActionEvent ae) {      
      setText((new Date()).toString());
  }    
}}